<link href="<?=site_url()?>css/jquery-ui-1.8.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?=base_url()?>js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>js/jquery-ui-1.8.custom.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>js/jquery.ui.datepicker-th.js"></script>
<style type="text/css">
.ui-datepicker {
	width: 13em;
}
.ui-widget {
	font-size: 1em;
}
</style>
<script language="javascript">
	$().ready(function() {
		$("#txtPasswdExpire").datepicker({
			showOn: 'button',
			buttonImage: '<?=site_url()?>images/calbtn.gif',
			buttonImageOnly: true,
			changeMonth: true,
			changeYear: true,
			yearRange: 'c-5:c+30'
		});	

		$("#txtBirthday").datepicker({
			showOn: 'button',
			buttonImage: '<?=site_url()?>images/calbtn.gif',
			buttonImageOnly: true,
			changeMonth: true,
			changeYear: true,
			yearRange: 'c-60:c'
		});	
	});
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function checkImageExt(obj) {
		var t = obj.value;
		var txt = obj.value.substring(obj.value.lastIndexOf(".")+1).toLowerCase();
		if(!(txt == "jpg" || txt == "jpeg" || txt == "gif" || txt == "png")) {
			alert("ไฟล์รูปภาพที่แนบมาไม่ถูกต้อง " + t + "\nกรุณาเลือกไฟล์ใหม่");	
			u = document.getElementById('uploader');
			u.innerHTML=' <input name="txtTutorImg" id="txtTutorImg" type="file" style="width:500px;" onchange="checkImageExt(this);" /> ';
		}
	}
	function handleTitle(val) {
		if(val.value == "อื่นๆ") {
			document.getElementById("txtTitleOther").readOnly = false;
			document.getElementById("txtTitleOther").className = "";
			document.getElementById("txtTitleOther").focus();
		} else {
			document.getElementById("txtTitleOther").readonly = true;
			document.getElementById("txtTitleOther").className = "textReadonly";
			document.getElementById("txtTitleOther").value = "";
		}
	}
	function validateForm() {
		if(trim(document.getElementById('txtFirstNameTh').value).length == 0) {
			document.getElementById('txtFirstNameTh').focus();
			alert("กรุณาใส่ชื่อ");
			return false;		
		} else if(trim(document.getElementById('txtLastNameTh').value).length == 0) {
			document.getElementById('txtLastNameTh').focus();
			alert("กรุณาใส่นามสกุล");
			return false;		
		} 
		var cc = document.getElementsByName('chkSchool[]'); 
	    for (var i = 0; i < cc.length; i++)  {
	        if(cc[i].checked == true)
		        return true; 
	    }
	    alert('กรุณาเลือกโรงเรียนในสังกัด อย่างน้อย 1 โรงเรียน');
	    return false;
	}
</script>
	
<div id="mainContent">
<?=form_open_multipart('TutorInfo/upload', array('onsubmit' => 'return validateForm();','autocomplete' => 'off'));?>
<input type="hidden" name="status" id="status" value="<?=$form_status?>" />
<input type="hidden" name="tutorId" id="tutorId"  <?php if(isset($tutor_id)) echo ' value="'.$tutor_id.'"';?>/>

<table width="1000px" border="0" cellspacing="2px" cellpadding="0" align="center" >
	<tr align="center">
    	<td>
    		<?php
    			if(isset($tutor_id)) {
    				echo ' <h2><b><font color="blue">'. $first_name_th .' ' . $last_name_th .'</font></h2> ';
					echo ' [<a href="'.base_url().'index.php/TutorInfo/detail/'.$tutor_id.'" >ประวัติส่วนตัว</a>] | 
						   [<a href="'.base_url().'index.php/TutorInfo/detailContractInfo/'.$tutor_id.'" >ข้อมูลการติดต่อ</a>]| 
						   [<a href="'.base_url().'index.php/TutorInfo/detailExp/'.$tutor_id.'" >ประวัติการทำงาน</a>]   | 
						   [<a href="'.base_url().'index.php/TutorInfo/detailTutorlandExp/'.$tutor_id.'" >ประวัติการสอนกับสถาบัน</a>] ';    				
    			} else {
    				echo " [ประวัติส่วนตัว] | [ข้อมูลการติดต่อ] | [ประวัติการทำงาน] | [ประวัติการสอนกับสถาบัน]";
    			}
    		?>	
    	</td>
    </tr>
    <tr align="center">
    	<td>
        	<table width="900px">
            	<tr>
                	<td align="left">
                    	วันที่ลงข้อมูลครั้งแรก <?php if($form_status == 'add') echo "-"; else echo $create_date; ?> 
                    	โดย <?php if($form_status == 'add') echo "-"; else echo $create_by; ?>            	
                    </td>
                    <td align="right">
                    	วันที่ลงข้อมูลครั้งล่าสุด <?php if($form_status == 'add' || $update_date == null) echo "-"; else echo $update_date; ?> 
                    	โดย <?php if($form_status == 'add' || $update_by == null) echo "-"; else echo $update_by; ?>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
	<tr style="height:10px;">
    	<td></td>
    </tr>
    <tr>
		<td align="center">
          <fieldset style="width: 950px;">
          <legend>ข้อมูลส่วนตัว</legend>
          <?php if($form_status != 'notPermit') {?>
                <table width="950px" border="0" cellspacing="2px" cellpadding="0">
                  <col width="150px" />
                  <col width="*" />
                  <col width="150px" />
                  
                  <tr>
                    <td align="right"><label>Username</label></td>
                    <td align="left"><input name="txtUsername" type="text" maxlength="20" value="<?php if($form_status != 'add' && (isset($username))) echo $username; ?>"/> 
                    <label>Password </label>
                    <input name="txtPassword" type="password" maxlength="20" value=""/> 
                    <label>หมดอายุ</label>
                    <input name="txtPasswdExpire" id="txtPasswdExpire" type="text" size="9" class="textReadonly" readonly="readonly" value="<?php if($form_status != 'add' && (isset($user_expire))) echo $user_expire; ?>"/>
                    </td>
                    <td rowspan="10"><img src="<?=site_url()?>data-image/tutor/<?php if($form_status == 'add' || $tutor_image == null) echo 'noImg.jpg'; else echo $tutor_image; ?>" width="150px" /></td>
                  </tr>
                  <tr>
                    <td align="right"><label>คำนำหน้าชื่อ</label></td>
                    <td align="left"><input name="radTitle" type="radio" id="radTitle1" value="นาย" <?php if($form_status == 'add' || (isset($title) && $title == 'นาย')) echo 'checked="checked"'; ?> onclick="handleTitle(this);" />
                      นาย
                      <input type="radio" name="radTitle" id="radTitle2" value="นาง" <?php if($form_status != 'add' && (isset($title) && $title == 'นาง')) echo 'checked="checked"'; ?> onclick="handleTitle(this);"/>
                      นาง
                      <input type="radio" name="radTitle" id="radTitle3" value="นางสาว" <?php if($form_status != 'add' && (isset($title) && $title == 'นางสาว')) echo 'checked="checked"'; ?> onclick="handleTitle(this);"/>
                      นางสาว
                      <input type="radio" name="radTitle" id="radTitle6" value="อื่นๆ" <?php if($form_status == 'add' || (isset($title) && ($title == 'นาย' || $title == 'นาง' || $title == 'นางสาว'))) echo ''; else echo 'checked="checked"';?> onclick="handleTitle(this);"/>
                      อื่นๆ
                      <input name="txtTitleOther" type="text" id="txtTitleOther" <?php if($form_status == 'add' || (isset($title) && ($title == 'นาย' || $title == 'นาง' || $title == 'นางสาว' ))) echo 'readonly="readonly" class="textReadonly"'; else echo ' value="'.$title.'"';?>  />            </td>
                  </tr>
                  <tr>
                    <td align="right"><label>ชื่อ</label></td>
                    <td align="left"><input name="txtFirstNameTh" id="txtFirstNameTh" type="text" maxlength="45"  value="<?php if($form_status != 'add' && (isset($first_name_th))) echo $first_name_th; ?>"/>
                        <span class="require">*</span>
                        <label> นามสกุล </label>
                        <input name="txtLastNameTh" id="txtLastNameTh" type="text" maxlength="45" value="<?php if($form_status != 'add' && (isset($last_name_th))) echo $last_name_th; ?>"/>
                      <span class="require">*</span> <label> ชื่อเล่น </label>
                        <input name="txtNickName" id="txtNickName" type="text" maxlength="45" value="<?php if($form_status != 'add' && (isset($nick_name))) echo $nick_name; ?>"/>
                      </td>
                  </tr>
                  <tr>
                    <td align="right"><label>First Name</label></td>
                    <td align="left"><input name="txtFirstNameEn" id="txtFirstNameEn" type="text" maxlength="45"  value="<?php if($form_status != 'add' && (isset($first_name_en))) echo $first_name_en; ?>"/>
                      
                      <label> Last Name</label>
                      <input name="txtLastNameEn" id="txtLastNameEn" type="text" maxlength="45" value="<?php if($form_status != 'add' && (isset($last_name_en))) echo $last_name_en; ?>"/>
                      </td>
                  </tr>
                  <tr>
                    <td align="right"><label>วัน เดือน ปี เกิด</label></td>
                    <td align="left"><input name="txtBirthday" type="text" class="textReadonly" id="txtBirthday" size="9" readonly="readonly"  value="<?php if($form_status != 'add' && (isset($birthday))) echo $birthday; ?>" />
                      </td>
                  </tr>
                  <tr>
                    <td align="right"><label>เลขที่บัตรประชาชน</label><br />
                      <label>หรือ passport</label></td>
                    <td align="left"><input name="txtCitizenId" id="txtCitizenId" type="text" maxlength="30" <?php if($form_status != 'add' && isset($citizen_id)) echo 'value="'.$citizen_id.'"';?> />
                        </td>
                  </tr>
                  <tr>
                    <td align="right" ><label>รูปถ่าย</label></td>
                    <td align="left"><div id='uploader'><input name="txtTutorImg" id="txtTutorImg" type="file" style="width:500px;" onchange="checkImageExt(this);" /></div></td>
                  </tr>
                   <tr>
                    <td align="right"><label>โรงเรียนที่สังกัด</label></td>
                    <td align="left">
                    	<?php
							foreach ($schoolList as $row) {
							    echo ' <input type="checkbox" name="chkSchool[]" value="'.$row->school_id .'"';
							    if(isset($schoolListCheck) && in_array($row->school_id, $schoolListCheck)) {
							    	echo ' checked="checked" ';
							    } 
							    echo ' /> '.$row->school_name.' ';
							}
                        ?>
					</td>
                  </tr>
                    <tr>
                    <td align="right" valign="top"><label>Black list ?</label></td>
                    <td align="left">
                      <input type="checkbox" name="chkBlackList" id="chkBlackList" value="Y" <?php if($form_status != 'add' && isset($isBlackList) && $isBlackList == 'Y') echo ' checked="checked"';?>/>
                      Black list 
                     <input name="txtBlackList" id="txtBlackList" type="text" style="width: 520px;" maxlength="250" <?php if($form_status != 'add' && isset($blackList_comment)) echo ' value="'.$blackList_comment.'"';?> /></td>
                  </tr>
                   <tr>
                    <td align="right" valign="top"><label>หมายเหตุอื่นๆ </label></td>
                    <td align="left">
                      <input name="txtComment" id="txtComment" type="text" style="width: 610px;" maxlength="250" <?php if($form_status != 'add' && isset($comment)) echo 'value="'.$comment.'"';?> /></td>
                  </tr>
                   <tr>
                    <td align="right" valign="top"><label>Resume </label></td>
                    <td align="left">
			<?php
				if(file_exists(FCPATH.'data-image/tutor/'.$hist_resume_path) AND $hist_resume_path!=''){
					echo '<a target="_blank" href="'.site_url().'data-image/tutor/'.$hist_resume_path.'">เรียกดู</a>';	
				}else{
					echo 'ไม่มี';
				}
			?>
		    </td>
                  </tr>
                  <tr style="height: 10px;">
                    <td align="right"></td>
                    <td align="left"></td>
                  </tr>
              </table>
              
          </fieldset>
		</td>
	</tr>
    <tr style="height:10px;">
    	<td></td>
    </tr>
    <tr>
		<td align="center">
          <fieldset style="width: 950px;">
          <legend>ประวัติิการศึกษา</legend>
                <table width="950px" border="0" cellspacing="2px" cellpadding="0">
                  <tr>
                    <td align="right" style="vertical-align:top;"><label>สถานะการศึกษา</label>
                    <br />
                    <br />
                    <br />
                    <label>ระดับการศึกษาปัจจุบัน</label></td>
                    <td align="left"><input name="rdEduStatus" type="radio" id="rdEduStatus1" value="1" <?php if(($form_status == 'add') ||($form_status != 'add' && isset($edu_status) && $edu_status == '1')) echo ' checked="checked"';?> />
จบการศึกษาแล้ว
  <br />
  <input name="rdEduStatus" type="radio" id="rdEduStatus2" value="2" <?php if($form_status != 'add' && isset($edu_status) && $edu_status == '2') echo ' checked="checked"';?>/>
                      กำลังศึกษาอยู่ (<span class="style3">โปรดกรอกข้อมูลด้านล่าง</span>)<br />
                      <table width="95%" border="0" cellspacing="2px" cellpadding="0" style="border:1px solid #999999">
                      <tr bgcolor="#33CCFF">
                        <td><div align="center">ระดับการศึกษา</div></td>
                        <td><div align="center">สถาบัน/มหาวิทยาลัย</div></td>
                        <td><div align="center">คณะ/สาขาวิชา</div></td>
                        <td><div align="center">รหัสนักศึกษา</div></td>
                        <td><div align="center">ชั้นปี</div></td>
                        <td><div align="center">เกรดเฉลี่ย</div></td>
                      </tr>
                      <tr>
                        <td><div align="center">
				<input type="text" name="studyingLevel" id="studyingLevel" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_current_level))) echo $edu_current_level; ?>" />
                          <!--<select name="studyingLevel" id="studyingLevel">
                            <option <?php if($form_status == 'add') echo ' selected="selected" ';?>>---โปรดเลือก---</option>
                            <option value="ปริญญาเอก" <?php if($form_status != 'add' && isset($edu_current_level) && $edu_current_level == 'ปริญญาเอก')  echo ' selected="selected" ';?>>ปริญญาเอก</option>
                            <option value="ปริญญาโท" <?php if($form_status != 'add' && isset($edu_current_level) && $edu_current_level == 'ปริญญาโท')  echo ' selected="selected" ';?>>ปริญญาโท</option>
                            <option value="ปริญญาตรี" <?php if($form_status != 'add' && isset($edu_current_level) && $edu_current_level == 'ปริญญาตรี')  echo ' selected="selected" ';?>> ปริญญาตรี</option>
                            <option value="มัธยมศึกษา" <?php if($form_status != 'add' && isset($edu_current_level) && $edu_current_level == 'มัธยมศึกษา')  echo ' selected="selected" ';?>>มัธยมศึกษา</option>
                          </select>-->
                        </div></td>
                        <td><div align="center">
                          <input type="text" name="studyingUniversity" id="studyingUniversity" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_current_university))) echo $edu_current_university; ?>" />
                        </div></td>
                        <td><div align="center">
                          <input type="text" name="studyingMajor" id="studyingMajor"  maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_current_department))) echo $edu_current_department; ?>"/>
                        </div></td>
                        <td><div align="center">
                          <input type="text" name="studyingID" id="studyingID"  maxlength="20" value="<?php if($form_status != 'add' && (isset($edu_current_student_id))) echo $edu_current_student_id; ?>"/>
                        </div></td>
                        <td><div align="center">
                          <input name="studyingClass" type="text" id="studyingClass" size="3"  maxlength="5" value="<?php if($form_status != 'add' && (isset($edu_current_class))) echo $edu_current_class; ?>"/>
                        </div></td>
                        <td><div align="center">
                          <input name="studyingGPA" type="text" id="studyingGPA" size="6"  maxlength="5" value="<?php if($form_status != 'add' && (isset($edu_current_GPA))) echo $edu_current_GPA; ?>"/>
                        </div></td>
                      </tr>
                    </table>                      </td>
                  </tr>
                  <tr style="height:10px;">
                  	<td></td>
                  </tr>
                  <tr>
                    <td align="right" style="vertical-align:top;"><label>ระดับการศึกษาที่จบแล้ว</label></td>
                    <td align="left"><table width="95%" border="0" cellspacing="2px" cellpadding="0" style="border:1px solid #999999">
                      <tr bgcolor="#33CCFF">
                        <td><div align="center">ระดับการศึกษา</div></td>
                        <td><div align="center">สถาบัน/มหาวิทยาลัย</div></td>
                        <td><div align="center">คณะ/สาขาวิชา</div></td>
                        <td><div align="center">รหัสนักศึกษา</div></td>
                        <td><div align="center">เกรดเฉลี่ย</div></td>
                      </tr>
                      <tr>
                        <td><div align="left">ประถมศึกษา</div></td>
                        <td><div align="center">
                            <input type="text" name="pratomSchool" id="pratomSchool" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_pratom_school))) echo $edu_pratom_school; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="pratomMajor" id="pratomMajor" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_pratom_major))) echo $edu_pratom_major; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="pratomID" id="pratomID" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_pratom_student_id))) echo $edu_pratom_student_id; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input name="pratomGPA" type="text" id="pratomGPA" size="6" maxlength="5" value="<?php if($form_status != 'add' && (isset($edu_pratom_GPA))) echo $edu_pratom_GPA; ?>"/>
                        </div></td>
                      </tr>
                      <tr>
                        <td><div align="left">มัธยมศึกษาตอนต้น</div></td>
                        <td><div align="center">
                            <input type="text" name="tonSchool" id="tonSchool" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_mo_tom_school))) echo $edu_mo_tom_school; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="tonMajor" id="tonMajor" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_mo_tom_major))) echo $edu_mo_tom_major; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="tonID" id="tonID" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_mo_tom_student_id))) echo $edu_mo_tom_student_id; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input name="tonGPA" type="text" id="tonGPA" size="6" maxlength="5" value="<?php if($form_status != 'add' && (isset($edu_mo_tom_GPA))) echo $edu_mo_tom_GPA; ?>"/>
                        </div></td>
                      </tr>
                      <tr>
                        <td><div align="left">มัธยมศึกษาตอนปลาย</div></td>
                        <td><div align="center">
                            <input type="text" name="paySchool" id="paySchool" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_mo_pay_school))) echo $edu_mo_pay_school; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="payMajor" id="payMajor" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_mo_pay_major))) echo $edu_mo_pay_major; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="payID" id="payID" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_mo_pay_student_id))) echo $edu_mo_pay_student_id; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input name="payGPA" type="text" id="payGPA" size="6" maxlength="5" value="<?php if($form_status != 'add' && (isset($edu_mo_pay_GPA))) echo $edu_mo_pay_GPA; ?>"/>
                        </div></td>
                      </tr>
                      <tr>
                        <td><div align="left">ปริญญาตรี</div></td>
                        <td><div align="center">
                            <input type="text" name="bSchool" id="bSchool" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_bachelor_university))) echo $edu_bachelor_university; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="bMajor" id="bMajor" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_bachelor_major))) echo $edu_bachelor_major; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="bID" id="bID" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_bachelor_student_id))) echo $edu_bachelor_student_id; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input name="bGPA" type="text" id="bGPA" size="6" maxlength="5" value="<?php if($form_status != 'add' && (isset($edu_bachelor_GPA))) echo $edu_bachelor_GPA; ?>"/>
                        </div></td>
                      </tr>
                      <tr>
                        <td><div align="left">ปริญญาโท</div></td>
                        <td><div align="center">
                            <input type="text" name="mSchool" id="mSchool" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_master_university))) echo $edu_master_university; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="mMajor" id="mMajor" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_master_major))) echo $edu_master_major; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="mID" id="mID" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_master_student_id))) echo $edu_master_student_id; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input name="mGPA" type="text" id="mGPA" size="6" maxlength="5" value="<?php if($form_status != 'add' && (isset($edu_master_GPA))) echo $edu_master_GPA; ?>"/>
                        </div></td>
                      </tr>
                      <tr>
                        <td><div align="left">ปริญญาเอก</div></td>
                        <td><div align="center">
                            <input type="text" name="dSchool" id="dSchool" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_doctor_university))) echo $edu_doctor_university; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="dMajor" id="dMajor" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_doctor_major))) echo $edu_doctor_major; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input type="text" name="dID" id="dID" maxlength="45" value="<?php if($form_status != 'add' && (isset($edu_doctor_student_id))) echo $edu_doctor_student_id; ?>"/>
                        </div></td>
                        <td><div align="center">
                            <input name="dGPA" type="text" id="dGPA" size="6" maxlength="5" value="<?php if($form_status != 'add' && (isset($edu_doctor_GPA))) echo $edu_doctor_GPA; ?>"/>
                        </div></td>
                      </tr>
                    </table></td>
                  </tr>
                  <tr style="height: 10px;">
                    <td align="right"></td>
                    <td align="left"></td>
                  </tr>
              </table>
              <?php } else echo '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>';  ?>
          </fieldset>
		</td>
	</tr>
	 <tr style="height:10px;">
    	<td></td>
    </tr>
	 <tr >
	 <?php if($form_status != 'notPermit') {?>
        <td align="center"><input name="" type="submit"  value="บันทึกข้อมูล"/>
        <br /></td>
     <?php } ?>
    </tr>
</table>
<?=form_close();?> 
</div>
